// pages/my/my.js
import {My} from "./my-model.js";
var my=new My();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{
      nickName:"老王",
      avatarUrl:"../../image/tabbar/my.png"
    },
    setting:[
      {
      text:"设置",
      style:"background-position:-425px -135px"
      },
      {
        text: "定时关闭",
        style: "background-position:-558px -175px"
      },
      {
        text: "WIFI",
        style: "background-position:-61px -1204px"
      },
      {
        text: "网络",
        style: "background-position:-245px -1121px"
      },
      {
        text:"扫码",
        style: "background-position:-377px -1202px"
      },
      {
        text:"拨打电话",
        style:"background-position:-472px -437px"
      }
    ]
  },

  onLoad:function(optios){
    my.getUserInfo((res)=>{
      this.setData({
        userInfo:res
      });
    });
  },

  onTap:function(e){
    var index=my.getDataSet(e,"index");
    var that=this;
    switch(index){
      case 0:{
        wx.openSetting({
          success:(res)=>{
            wx.navigateTo({
              url: '../success/success',
            })
          }
        });
        break;
      }
      case 1:{
        wx.navigateTo({
          url: '../time/time',
        });
        break;
      }
      case 2:{
        wx.navigateTo({
          url: '../wifi/wifi',
        });
        break;
      }
      case 3:{
        
        break;
      }
      case 4:{
        wx.scanCode({
          success:function(res){
            wx.setStorageSync("code",res);
            wx.navigateTo({
              url: '../scanCode/scanCode',
            });
          }
        });
        break;
      }
      case 5:{
        wx.navigateTo({
          url: '../phone/phone',
        });
      }
      case 5: {
        
      }
    }
  },

  onShow:function(){
    var that=this;
    wx.getNetworkType({
      success: function (res) {
        that.setData({
          networkType: res.networkType
        });
      },
    });

    wx.onNetworkStatusChange(function(res){
      var network="";
      if(res.isConnected){
        network=res.networkType;
      }else{
        network="无网路";
      }
      that.setData({
        networkType:network
      });
    });
  }
})